package cn.e3mall.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.e3mall.common.util.E3Result;
import cn.e3mall.common.util.JsonUtils;
import cn.e3mall.pojo.TbItem;
import cn.e3mall.service.ItemService;

/**
 * 商品管理 Controller
 * @author zhouzhixiang
 *
 */

@Controller
public class ItemController {

	@Autowired 
	private ItemService itemService;
	
	@RequestMapping("/item/{itemId}")
	@ResponseBody
	public TbItem getItemById(@PathVariable Long itemId){
		TbItem tbItem= itemService.getItemById(itemId);
		return tbItem;
	}
	
	@RequestMapping(value="/item/save",method=RequestMethod.POST)
	@ResponseBody
	public E3Result addItem(TbItem item,String desc){
		E3Result result=itemService.addItem(item, desc);
		return result;
	}
	
	
	@RequestMapping(value="/rest/item/query/item/desc/{id}")
	@ResponseBody
	public E3Result showTtemDesc(@PathVariable Long id){
		E3Result result = itemService.showItemDesc(id);
		return result;
	}
	
	@RequestMapping(value="/rest/item/param/item/query/{id}")
	@ResponseBody
	public E3Result showTtem(@PathVariable Long id){
		E3Result result = itemService.showItem(id);
		return result;
	}
	
	
	@RequestMapping(value="/rest/item/update",method=RequestMethod.POST)
	@ResponseBody
	public E3Result editTtem(TbItem item,String desc){
		E3Result result = new E3Result();
		result=itemService.editItem(item, desc);
		return result;
	}
	
	@RequestMapping("/rest/item/delete")
	@ResponseBody
	public E3Result delItem(Long ids){
		E3Result result = itemService.delItem(ids);
		return E3Result.ok();
	}
	
}
